﻿<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8" />
    <title>导航菜单详情</title>
    <link href="../lib/layui/css/layui.css" rel="stylesheet" />
    <link href="../x-admin/css/font.css" rel="stylesheet" />
    <link href="../x-admin/css/xadmin.css" rel="stylesheet" />
</head>
<body>
    <div class="layui-card-body" style="">
        <form class="layui-form" id="navform" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">ID</label>
                <div class="layui-input-block">
                    <input type="text" name="id" required  readonly lay-verify="required" placeholder="请输入ID" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">CODE</label>
                <div class="layui-input-block">
                    <input type="text" name="code" required lay-verify="required" placeholder="请输入CODE" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" required lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">文件夹</label>
                <div class="layui-input-block">
                    <input type="text" name="directory"  placeholder="请输入文件夹" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">层级</label>
                <div class="layui-input-block">
                    <input type="text" name="level" required lay-verify="required" placeholder="请输入层级" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">父ID</label>
                <div class="layui-input-block">
                    <input type="text" name="parentid"  placeholder="请输入父ID" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">是否启用</label>
                    <div class="layui-input-inline">
                        <input type="checkbox" name="navicatflag" lay-skin="switch">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">是否统计</label>
                    <div class="layui-input-inline">
                        <input type="checkbox" name="isstatistics" lay-skin="switch">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">是否目录</label>
                    <div class="layui-input-inline">
                        <input type="checkbox" name="isdirectory" lay-skin="switch">
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图标</label>
                <div class="layui-input-block">
                    <input type="text" name="img" required lay-verify="required" placeholder="请输入图标" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">链接地址</label>
                <div class="layui-input-block">
                    <input type="text" name="href" placeholder="请输入地址" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">显示序号</label>
                <div class="layui-input-block">
                    <input type="text" name="index" required lay-verify="required" placeholder="请输入序号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea name="note" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="formsub">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>
    <script src="../lib/layui/layui.js"></script>
    <script type="text/javascript" src="../lib/Base64/base64.min.js"></script>
    <script>
        function getrequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        }
        layui.$().ready(function () {
            var $ = layui.$;
            var itemtemp = getrequest().iteminfo;
            if (itemtemp != "") {
                var item = JSON.parse(window.decodeURIComponent(atob(itemtemp)));
                $("input[name='id']").val(item.id);
                $("input[name='code']").val(item.code);
                $("input[name='name']").val(item.name);
                $("input[name='directory']").val(item.directory);
                $("input[name='level']").val(item.level);
                $("input[name='parentid']").val(item.parentId);
                if (item.navicatFlag == 1) {
                    // 设置复选框微勾选状态
                    $("input[name='navicatflag']").attr('checked', 'checked');
                } else {
                    // 设置复选框未选中状态
                    $("input[name='navicatflag']").removeAttr('checked');
                }
                if (item.isStatistics == 1) {
                    // 设置复选框微勾选状态
                    $("input[name='isstatistics']").attr('checked', 'checked');
                } else {
                    // 设置复选框未选中状态
                    $("input[name='isstatistics']").removeAttr('checked');
                }
                if (item.isDirectory == 1) {
                    // 设置复选框微勾选状态
                    $("input[name='isdirectory']").attr('checked', 'checked');
                } else {
                    // 设置复选框未选中状态
                    $("input[name='isdirectory']").removeAttr('checked');
                }
                $("input[name='img']").val(item.img);
                $("input[name='href']").val(item.href);
                $("input[name='index']").val(item.index);
                $("textarea[name='note']").val(item.note);
                layui.form.render('checkbox');
            }
            else {
                //新增数据；
                $("input[name='id']").removeAttr('readonly');
            }
        });
        layui.use('form', function () {
            var form = layui.form;
            //监听提交
            form.on('submit(formsub)', function (data) {
                layer.msg(JSON.stringify(data.field));
                layui.$.ajax({
                    type: "post",
                    url: localStorage.getItem('hosttingaddr') + '/api/main/updatemenusnav',
                    data: layui.$('#navform').serialize(),
                    //data: JSON.stringify(data.field),
                    success: function (data) {
                       //if (data == "success") {
                            layer.msg('更新完成!', { icon: 1, time: 1000 });
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                            parent.layer.close(index);
                        //}
                    },
                    error: function (data) {
                        layer.msg('更新失败!', { icon: 1, time: 1000 });
                        window.parent.location.reload();
                        var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
                        parent.layer.close(index);
                    }
                });
                return false;
            });
        });
    </script>
</body>
</html>